home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998…tember: Reference Library / Dev.CD Sep 98 RL1.toast / Technical Documentation / develop / develop Issue 27 / develop Issue 27 code / Internet Config Assistant / toolkit / macros.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-07  |  2.2 KB  |  140 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        macros.h
  3.  
  4.     Contains:    Definition of various useful macros and inlines
  5.  
  6.     Written by:    Arno Gourdol
  7.  
  8.     Copyright:    © 1994-1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <3>      2/1/96    timbo   Remove kScrollbarWidth; already defined in d11e1 headers.
  13.          <2>      5/3/95    TM        Merge with InfoAccess version.
  14.          <1>     4/12/95    djc        First checked in.
  15.          <6>     3/28/95    RR        Removed HiWord and LoWord functions
  16.          <5>    10/27/94    RR        added LowWord and HighWord Functions
  17.          <4>     9/19/94    JwK        Max macro should be pin
  18.          <3>     7/25/94    JJ         Removed String Macros
  19.          <2>     7/25/94    JJ            Added string macros
  20.          <1>     7/15/94    arno        first checked in
  21.          <3>     7/14/94    arno        Clean-up
  22.         <1+>     6/10/94    arnoo        Added PascalString macro
  23.  
  24. */
  25.  
  26. /*
  27.   This file contains some frequently used macros:
  28.  
  29.   short min(short, short)
  30.   short max(short, short)
  31.   short pin(short value, short lowerBounds, short upperBound)
  32.  
  33.   long abs(long)
  34.   long min(long, long)
  35.   long max(long, long)
  36.   long pin(long value, long lowerBounds, long upperBound)
  37.  
  38. */
  39.  
  40.  
  41. #pragma once
  42.  
  43. #ifndef __MACROS__
  44. #define __MACROS__
  45.  
  46. #include <Types.h>
  47. #include <Memory.h>
  48.  
  49. #ifdef __cplusplus
  50. //
  51. // C++ Versions of the macros 
  52. //
  53.  
  54. inline unsigned short HighWord(long l)
  55. {
  56.     return (unsigned short)((l >> 16) & 0xFFFF);
  57. }
  58.  
  59.  
  60. inline unsigned short LowWord(long l)
  61. {
  62.     return (unsigned short)(l & 0xFFFF);
  63. }
  64.  
  65.  
  66. inline short min(short a,
  67.                  short b)
  68. {
  69.     return a > b ? b : a;
  70. }
  71.  
  72.  
  73. inline short max(short a,
  74.                  short b)
  75. {
  76.     return a > b ? a : b;
  77. }
  78.  
  79.  
  80. inline long min(long a,
  81.                 long b)
  82. {
  83.     return a > b ? b : a;
  84. }
  85.  
  86.  
  87. inline long max(long a,
  88.                 long b)
  89. {
  90.     return a > b ? a : b;
  91. }
  92.  
  93.  
  94. inline short pin(short value,
  95.                  short min,
  96.                  short max)
  97. {
  98.     return value < min ? min : (value > max ? max : value);
  99. }
  100.  
  101.  
  102. inline long pin(long value,
  103.                 long min,
  104.                 long max)
  105. {
  106.     return value < min ? min : (value > max ? max : value);
  107. }
  108.  
  109.  
  110. inline short abs(short x)
  111. {
  112.     return x < 0 ? -x : x;
  113. }
  114.  
  115. inline long abs(long x)
  116. {
  117.     return x < 0 ? -x : x;
  118. }
  119.  
  120. #else
  121. //
  122. // C Versions of the macros 
  123. //
  124.  
  125. #ifndef min
  126. #define min(a,b) ((a)>(b)?(b):(a))
  127. #endif
  128.  
  129. #ifndef max
  130. #define max(a,b) ((a)>(b)?(a):(b))
  131. #endif
  132.  
  133. #ifndef pin
  134. #define pin(value,min,max) ((value) < (min) ? (min) : ((value) > (max) ? (max) : (value)))
  135. #endif
  136.  
  137. #endif
  138.  
  139.  
  140. #endif